﻿using data.jianvgroup.com.Entity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace data.jianvgroup.com
{
    public class JvgroupContext:IdentityDbContext<jvuser>
    {
        public JvgroupContext(DbContextOptions<JvgroupContext> options) :base(options) { }

        public JvgroupContext():base(){ }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            => optionsBuilder.UseMySql("server=rm-uf6c51875112oq98ko.mysql.rds.aliyuncs.com;user id=dbuser;password=www163comM;database=jianvgroup_test");

        public DbSet<News> news { get; set; }

        public DbSet<Recruitment> recruitment { get; set; }

        public DbSet<CompanyStories> companyStories { get; set; }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
           
            builder.Entity<jvuser>(entity => entity.Property(m => m.Id).HasMaxLength(255));
            builder.Entity<jvuser>(entity => entity.Property(m => m.NormalizedEmail).HasMaxLength(255));
            builder.Entity<jvuser>(entity => entity.Property(m => m.NormalizedUserName).HasMaxLength(255));

            builder.Entity<IdentityRole>(entity => entity.Property(m => m.Id).HasMaxLength(255));
            builder.Entity<IdentityRole>(entity => entity.Property(m => m.NormalizedName).HasMaxLength(255));

            builder.Entity<IdentityUserLogin<string>>(entity => entity.Property(m => m.LoginProvider).HasMaxLength(255));
            builder.Entity<IdentityUserLogin<string>>(entity => entity.Property(m => m.ProviderKey).HasMaxLength(255));
            builder.Entity<IdentityUserLogin<string>>(entity => entity.Property(m => m.UserId).HasMaxLength(255));

            builder.Entity<IdentityUserRole<string>>(entity => entity.Property(m => m.UserId).HasMaxLength(255));
            builder.Entity<IdentityUserRole<string>>(entity => entity.Property(m => m.RoleId).HasMaxLength(255));

            builder.Entity<IdentityUserToken<string>>(entity => entity.Property(m => m.UserId).HasMaxLength(255));
            builder.Entity<IdentityUserToken<string>>(entity => entity.Property(m => m.LoginProvider).HasMaxLength(255));
            builder.Entity<IdentityUserToken<string>>(entity => entity.Property(m => m.Name).HasMaxLength(255));

            builder.Entity<IdentityUserClaim<string>>(entity => entity.Property(m => m.Id).HasMaxLength(255));
            builder.Entity<IdentityUserClaim<string>>(entity => entity.Property(m => m.UserId).HasMaxLength(255));
            builder.Entity<IdentityRoleClaim<string>>(entity => entity.Property(m => m.Id).HasMaxLength(255));
            builder.Entity<IdentityRoleClaim<string>>(entity => entity.Property(m => m.RoleId).HasMaxLength(255));

            builder.Entity<News>(entity => entity.Property(m => m.Content).HasColumnType("text"));
            builder.Entity<Recruitment>(entity => entity.Property(m => m.Description).HasColumnType("text"));

        }
    }
}
